﻿using System;

namespace Yd.CommCls
{
    public static class LJString
    {
        /// <summary>
        /// 将字符串转换为Int
        /// </summary>
        /// <param name="t"></param>
        /// <returns>当转换失败时返回0</returns>
        public static int StrToInt(this string s)
        {
            int _i=0;
            int.TryParse(s, out _i);
            return _i;
        }

        /// <summary>
        /// 将字符串转换为decimal
        /// </summary>
        /// <param name="s"></param>
        /// <returns>当转换失败时返回0</returns>
        public static decimal StrTodecimal(this string s)
        {
            decimal d=0;
            decimal.TryParse(s, out d);
            return d;
        }

        /// <summary>
        /// 将字符串转换为时间
        /// </summary>
        /// <param name="s"></param>
        /// <returns>当转换失败时返回0001-01-01 00:00:00</returns>
        public static DateTime StrToDateTime(this string s)
        {
            DateTime _t=DateTime.Now;
            if (!DateTime.TryParse(s, out _t))
            {
                return DateTime.Now;
            }
            return _t;
        }

    }
}
